package com.msb.mall.produce.controller;

import java.util.Arrays;
import java.util.Map;

import com.msb.mall.produce.vo.AttrResponseVo;
import com.msb.mall.produce.vo.AttrVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.msb.mall.produce.entity.AttrEntity;
import com.msb.mall.produce.service.AttrService;
import com.msb.common.utils.PageUtils;
import com.msb.common.utils.R;



/**
 * 商品属性
 *
 * @author liufei
 * @email 1583409404@qq.com
 * @date 2023-10-31 22:59:47
 */
@RestController
@RequestMapping("produce/attr")
public class AttrController {
    @Autowired
    private AttrService attrService;


    /**
     * 列表
     */
    @GetMapping("/{attrType}/list/{catelogId}")
    @RequiresPermissions("produce:attr:list")
    public R baseList(@RequestParam Map<String, Object> params, @PathVariable Long catelogId,
                      @PathVariable String attrType){
        PageUtils page = attrService.queryBasePage(params, catelogId, attrType);

        return R.ok().put("page", page);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("produce:attr:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = attrService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{attrId}")
    @RequiresPermissions("produce:attr:info")
    public R info(@PathVariable("attrId") Long attrId){
		// AttrEntity attr = attrService.getById(attrId);
        AttrResponseVo vo =  attrService.getAttrInfo(attrId);

        return R.ok().put("attr", vo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("produce:attr:save")
    public R save(@RequestBody AttrVO vo){
		//attrService.save(attr);
        attrService.saveAttr(vo);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("produce:attr:update")
    public R update(@RequestBody AttrVO attrVO){
		//attrService.updateById(attr);
        attrService.updateBaseAttr(attrVO);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("produce:attr:delete")
    public R delete(@RequestBody Long[] attrIds){
		// attrService.removeByIds(Arrays.asList(attrIds));
        attrService.removeByIdsDetail(Arrays.asList(attrIds));
        return R.ok();
    }

}
